#pragma once

#include <queue>
#include <fstream>
#include "CommandHandler.h"
#include "Recorder.h"
#include "LogWriter.h"



class VoiceRecognizer : public exl::ps::ThreadBase, public SoundBufferConsumer
{
	static const int sampleRate = 16000;


	std::queue <SoundBuffer *> buffers;
	std::string configFileName;
	LogWriter log;
	int milliseconds;

	ICommandHandler * commandHandler;


	// Methods;
	bool exceptionHandler(void * address, int code);
	int recognitionLoop();


public:
	VoiceRecognizer(const std::string & configFileName, int milliseconds = 500)
		: configFileName(configFileName), log(""), milliseconds(milliseconds), commandHandler(NULL)
	{ }

	VoiceRecognizer(const std::string & configFileName, const std::string & logFileName, int milliseconds = 500)
		: configFileName(configFileName), log(logFileName), milliseconds(milliseconds), commandHandler(NULL)
	{ }

	inline void setCommandHandler(ICommandHandler & wh)
	{
		commandHandler = &wh;
	}

	
	void appendBuffer(SoundBuffer & sb);

	int run();
};
